package com.hyperfix.washer.controller;

import com.hyperfix.common.auth.RequiresRole;
import com.hyperfix.models.common.R;
import com.hyperfix.models.washer.pojos.ParamConfig;
import com.hyperfix.models.washer.vos.ParamConfigVO;
import com.hyperfix.washer.service.ParamConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author JiangChunYu
 * 2024/4/24
 */
@Validated
@RestController
@RequestMapping("/paramConfig")
public class ParamConfigController {
    @Resource
    private ParamConfigService paramConfigService;

    /**
     * 添加或更新报警参数配置
     *
     * @param paramConfigVO 报警参数配置 VO
     * @return {@link R}<{@link String}>
     */
    @RequiresRole("admin")
    @PostMapping("/addOrUpdate")
    public R<String> addOrUpdate(@RequestBody @Validated ParamConfigVO paramConfigVO) {
        return paramConfigService.addOrUpdate(paramConfigVO);
    }

    /**
     * 获取指定管道的报警参数配置
     *
     * @param pipelineId 管道 ID
     * @return {@link R}<{@link List}<{@link ParamConfig}>>
     */
    @PostMapping("/getOne/{pipelineId}")
    public R<List<ParamConfig>> getOnePipelineParamConfig(@PathVariable("pipelineId") @NotNull Integer pipelineId) {
        return paramConfigService.getOnePipelineParamConfig(pipelineId);
    }
}